<template>
  <div>
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="4" :sm="12">
            <a-form-item label="期数">
              <a-input-number :min="1" v-model="queryParam.phase" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="12">
            <a-form-item label="栋数">
              <a-input-number :min="1" v-model="queryParam.building" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="12">
            <a-form-item label="单元">
              <a-input-number :min="1" v-model="queryParam.unit" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="12">
            <a-form-item label="楼层">
              <a-input-number :min="1" v-model="queryParam.floor" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="12">
            <a-form-item label="房号">
              <a-input-number :min="1" v-model="queryParam.number" placeholder=""/>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="12">
            <a-form-item label="姓名">
              <a-input v-model="queryParam.name" placeholder=""/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="48">
          <a-col :md="20" :sm="60">
          </a-col>
          <a-col :md="4" :sm="12">
            <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleEdit()">新增</a-button>
    </div>

    <s-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :data="loadData"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
      <!-- 体温状态插槽 -->
      <span slot="temperature" slot-scope="text, record">
        <a-badge :status="record.temperature == 0 ? 'success' : 'error'" :text="record.temperature == 0 ? '正常' : '异常'" />
      </span>
    </s-table>
  </div>
</template>

<script>
import moment from 'moment'
import { STable } from '@/components'
import { getPassrecordList } from '@/api/passrecord'

export default {
  name: 'TableList',
  components: {
    STable
  },
  data () {
    return {
      mdl: {},
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        // {
        //   title: '序号',
        //   scopedSlots: { customRender: 'serial' }
        // },
        // {
        //   title: '#ID',
        //   dataIndex: 'id',
        //   width: 2
        // },
        {
          title: '期数',
          dataIndex: 'phase'
        },
        {
          title: '栋数',
          dataIndex: 'building'
        },
        {
          title: '单元',
          dataIndex: 'unit'
        },
        {
          title: '楼层',
          dataIndex: 'floor'
        },
        {
          title: '房号',
          dataIndex: 'number'
        },
        {
          title: '姓名',
          dataIndex: 'name'
        },
        {
          title: '出行方向',
          dataIndex: 'direct',
          customRender: (text) => text === 0 ? '外出' : '进入'
        },
        {
          title: '体温',
          dataIndex: 'temperature',
          scopedSlots: { customRender: 'temperature' }
        },
        {
          title: '备注',
          dataIndex: 'remark'
        },
        {
          title: '录入时间',
          dataIndex: 'createdTime'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        console.log('loadData.parameter', parameter)
        const params = Object.assign(parameter, this.queryParam)
        const keys = Object.keys(params)
        for (let i = 0; i < keys.length; i++) {
          if (params[keys[i]] == null) {
            delete params[keys[i]]
          }
        }
        return getPassrecordList(params)
          .then(res => {
            return res
          })
      },
      selectedRowKeys: [],
      selectedRows: []
    }
  },
  created () {
  },
  methods: {

    handleEdit (record) {
      this.$emit('onEdit', record)
    },
    handleOk () {

    },

    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    resetSearchForm () {
      this.queryParam = {
        date: moment(new Date())
      }
    }
  }
}
</script>
